<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>

<form:form commandName="role" cssClass="form-horizontal" role="form">
    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="roleName_edit">角色名称</label>
        <div class="col-sm-4">
            <input type="text" autocomplete='off' placeholder="必填" name="roleName" id="roleName_edit"
                   value="<c:out value="${role.roleName}"/>"
                   class="form-control " title="<c:out value="${role.roleName}"/>" required/>
        </div>
        <label class="col-sm-1 control-label no-padding-right" for="roleAuth_select">角色权限</label>
        <div class="col-sm-4">
            <select class="form-control" name="roleAuth" id="roleAuth_select">
                <option value="">选择角色权限（非必选）</option>
                <option value="1">权限1</option>
                <option value="2">权限2</option>
                <option value="3">权限3</option>
                <option value="4">权限4</option>
            </select>
        </div>
    </div>
    <form:hidden path="sysId"/>
</form:form>
<script>
    $(function () {
        $("#roleName_edit").blur(function () {
            var roleName = $("#roleName_edit").val();
            debugger;
            var roleName_old = '${role.roleName}';
            $.ajax({
                type: "GET",
                url: "/api/role/queryRoleNameExist",
                dataType: "json",
                data: {roleName: roleName},
                success: function (model) {
                    if (model.code == "1" && roleName_old != roleName) {
                        alert("单位:‘" + roleName + "’系统已存在，不需要重新添加！");
                        $("#deptName_edit").val(roleName_old);
                    }
                },
                error: function (model) {
                }
            });
        });
        var roleAuth = ${role.roleAuth};
        $("#roleAuth_select").val(roleAuth);
    })
</script>